var ProcessDefinitionManaged = function() {
	return {
		datatable : null,
		init : function() {
			this.initSearch();
			this.initListener();
		},
		initSearch : function() {
			if (!jQuery().dataTable) {
				return;
			}
			var pictureTable = $("#processDefinitionListTable").dataTable({
				"sAjaxSource" : ctx + "/process/definition/search?now=" + new Date().getTime(),
				/* 使用post方式 */
				"fnServerData" : function(sSource, aoData, fnCallback) {
					var postData = {
						page : 1,
						start : 0,
						rows : 10,
						params : {}
					};
					// 参数
					for (var i = 0, size = aoData.length; i < size; i++) {
						if (aoData[i].name == 'iDisplayLength') {
							postData.rows = aoData[i].value;
						} else if (aoData[i].name == 'iDisplayStart') {
							postData.start = aoData[i].value;
						} else if (aoData[i].name == 'sEcho') {
							postData.page = aoData[i].value;
						}
					}
					
					if($('#name').val()){
						postData.params.processName = $('#name').val();
					}

					$.ajax({
						"dataType" : 'json',
						"type" : "POST",
						"cache": false,
						"url" : sSource,
						"data" : postData,
						"success" : function(data, textStatus, jqXHR){
							fnCallback(data.data, textStatus, jqXHR);
						}
					});
				},
				"bAutoWidth":false,
				"aoColumnDefs" : [
						
						{
							"data" : "index",
							"aTargets" : [ 0 ]
						},{
							"data" : "id",
							"aTargets" : [ 1 ]
						},
						{
							"data" : "name",
							"aTargets" : [ 2 ]
						},
						{
							"data" : "key",
							"aTargets" : [ 3 ]
						},
						{
							"data" : "version",
							"aTargets" : [ 4 ]
						},{
							"data" : "resourceName",
							"aTargets" : [ 5 ]
						},{
							"data" : "diagramResourceName",
							"aTargets" : [ 6 ]
						},{
							"data" : "deploymentId",
							"aTargets" : [ 7 ]
						},
						{
							"aTargets" : [ 8 ],
							"mRender" : function(data, type, full) {
								var btns =  "<a href='"+ ctx +"/process/definition/showView.action?deploymentId="+full.deploymentId+"&diagramResourceName="+full.diagramResourceName+"' target='_blank'>查看流程图</a>";
								return btns;
							}
						} ]
			});
			this.datatable = pictureTable;
		},
		reSearch:function(){
        	this.datatable.fnDraw();
        },removeClass:function(){//去除Form表单的验证样式
        	$('.form-group','#actForm').removeClass('has-success')
            .removeClass('has-error');
    		 $('span').remove('.help-block');
        },initListener : function() {
			/*
			 * 查询
			 */
			$("#searchBtn").click(function() {
				ProcessDefinitionManaged.reSearch();
				return false;
			});

			/*
			 * 清除
			 */
			$("#clearBtn").click(function() {
				$("#searchForm")[0].reset();
				return false;
			});
		}
	};
}();